package com.honey.solr.analyzer;

import com.honey.compilation.xml.XmlElement;

public abstract class BaseAnalyzer implements SolrAnalyzerNode{
	
	@Override
	public void appendChildNode(XmlElement root) {
		XmlElement answer = new XmlElement(root,"fieldType");
		answer.addAttribute("name", getFieldTypeName());
		answer.addAttribute("class", "solr.TextField");
		answer.addAttribute("positionIncrementGap", "100");
		
		
		XmlElement index = getIndexTokenizer();
		appendFilter(index);
		XmlElement query = getQueryTokenizer();
		appendFilter(query);
		
		answer.addElement(index);
		answer.addElement(query);
		String doc = getXmlDoc();
		if(doc != null) answer.addXmlDoc(doc);
		
	}
	
	public abstract XmlElement getIndexTokenizer() ;
	
	public abstract XmlElement getQueryTokenizer() ;
	
	public abstract String getXmlDoc() ;
	
	public abstract String getFieldTypeName() ;
	
	private void appendFilter(XmlElement parent){
		new XmlElement(parent,"filter")
		.addAttribute("class", "solr.StopFilterFactory")
		.addAttribute("ignoreCase", "true")
		.addAttribute("words", "stopwords.txt")
		.addAttribute("enablePositionIncrements", "true")
		;
		
//		new XmlElement(parent,"filter")
//		.addAttribute("class", "solr.WordDelimiterFilterFactory")
//		.addAttribute("generateWordParts", "1")
//		.addAttribute("generateNumberParts", "1")
//		.addAttribute("catenateWords", "0")
//		.addAttribute("catenateNumbers", "0")
//		.addAttribute("catenateAll", "0")
//		.addAttribute("splitOnCaseChange", "0")
//		;
		new XmlElement(parent,"filter")
		.addAttribute("class", "solr.LowerCaseFilterFactory")
		;
		
//		new XmlElement(parent,"filter")
//		.addAttribute("class", "solr.EnglishPorterFilterFactory")
//		.addAttribute("protected", "protwords.txt")
//		;
//		new XmlElement(parent,"filter")
//		.addAttribute("class", "solr.RemoveDuplicatesTokenFilterFactory")
//		;
	}
}
